from wcferry import Wcf


class RobotUtil:
    @classmethod
    def getAllContacts(cls, wcf: Wcf) -> dict:
        """
        获取联系人（包括好友、公众号、服务号、群成员……）
        格式: {"wxid": "NickName"}
        """
        contacts = wcf.query_sql("MicroMsg.db", "SELECT UserName, NickName FROM Contact;")
        return {contact["UserName"]: contact["NickName"] for contact in contacts}

    @classmethod
    def getNickNameByWxid(cls, wxid, wcf: Wcf):
        """
        根据wxid获取昵称
        """
        all_contacts = cls.getAllContacts(wcf)
        if wxid in all_contacts:
            return all_contacts[wxid]
        else:
            return ""
